package com.iman.sumer.service.impl.teamgroup;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import com.iman.common.hibernate.TemplateQLService;
import com.iman.common.support.Page;
import com.iman.sumer.service.teamgroup.GroupActivityService;
import com.iman.sumer.vo.teamgroup.GroupActivityVo;

@Service
public class GroupActivityServiceImpl implements GroupActivityService {
	@Inject
    private TemplateQLService templateQLService;


	@Override
	public Page<GroupActivityVo> getActivityList(Map<String, Object> params) {
		Integer ps = Integer.valueOf(params.get("ps").toString());
		Integer pn = Integer.valueOf(params.get("pn").toString());
		params.put("startNo", ps*pn);
 		Page<GroupActivityVo> vos = templateQLService.findByPagedSQLBeanQuery(
				"group_activity_list", params, Page.getStartOfPage(pn, ps), ps,
				GroupActivityVo.class);
		return vos;
	}

	@Override
	public List<GroupActivityVo> getGroupActivityList(Map<String, Object> params) {
		List<GroupActivityVo> vos = templateQLService.findBySQLMapQuery("group_activity_list", params);
		return vos;
	}
	
	@Override
	public Map getGroupActivityByID(Map params) {
		List<Map> vos = templateQLService.findBySQLMapQuery("activity_by_id", params);
		if(vos!=null && !vos.isEmpty()){
			return vos.get(0);
		}
		return null;
	}
	
	@Override
	public List<Map> getActivityMemberByID(Map params) {
		List<Map> list = templateQLService.findBySQLMapQuery("activity_members_by_id", params);
		if(list.size() == 1){
			boolean flag = true;
			Map map = list.get(0);
			for(Object obj : map.keySet()){
				if(map.get(obj)!=null && !"null".equals(map.get(obj))){
					flag = false;
				}
			}
			if(flag){
				return null;
			}
		}
		return list;
	}
	
	
	@Override
	public int updateGroupActivity(Map params) {
		return templateQLService.executeSQLUpdate("activity_update", params);
	}
	

	@Override
	public List<Map> getGroupActivityListTop3(Map<String, Object> params) {
		List<Map> vos = templateQLService.findBySQLMapQuery("group_dynamic_list_top3", params);
		return vos;
	}

	@Override
	public void addGroupActivity(Map params) {
		templateQLService.executeSQLUpdate("add_group_activity", params);
	}

	@Override
	public void deleteActivity(Map params) {
		templateQLService.executeSQLUpdate("activity_delete", params);
	}

	@Override
	public void addMembersActicity(Map params) {
		// TODO Auto-generated method stub
		templateQLService.executeSQLUpdate("activity_add_members", params);
	}

	@Override
	public Map getUserById(Long create_user_id) {
		Map params = new HashMap();
		params.put("user_id", create_user_id);
		List<Map> vos = templateQLService.findBySQLMapQuery("user_by_id", params);
		if(vos!=null && !vos.isEmpty()){
			return vos.get(0);
		}
		return null;
	}
	
	

}
